package com.zmn.oms.admin.controller.conf.tips;

import com.zmn.common.dto2.ResponseDTO;
import com.zmn.common.utils.collection.CollectionUtil;
import com.zmn.mcc.cas.model.LoginStaff;
import com.zmn.mcc.cas.web.StaffAdminService;
import com.zmn.oms.admin.controller.OmsBaseController;
import com.zmn.oms.business.interfaces.tipsconfig.PictureTipsConfigBService;
import com.zmn.oms.model.dio.conf.tips.PictureTipsConfigDTO;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Objects;


/**
 * 安全提示配置Controller
 *
 * @author weilai
 * @since 2022-08-02 14:11:21
 */
@RestController
@RequestMapping("/tips/config/")
@Slf4j
public class PictureTipsConfigModifyController extends OmsBaseController {
    @Resource
    private PictureTipsConfigBService pictureTipsConfigBService;

    /**
     * 描述: 修改新增
     *
     * @param dto 入参
     * @return
     * @author weilai
     * @since 2022-08-02 14:11:21
     */
    @RequestMapping("addModify")
    @RequiresPermissions("/tips/config/addModify.action")
    public ResponseDTO addModify(@RequestBody PictureTipsConfigDTO dto) {
        if (Objects.isNull(dto) || (CollectionUtil.isNullOrEmpty(dto.getTipsConfigList())
                && CollectionUtil.isNullOrEmpty(dto.getDelListId()))) {
            return ResponseDTO.fail("请上传图片！");
        }
        pictureTipsConfigBService.batchAdd(dto, getMcStaffRealName());

        return ResponseDTO.success("图片添加成功！");
    }

    /**
     * 获取登录用户名
     *
     * @param
     * @return
     */
    public String getMcStaffRealName() {
        LoginStaff staff = StaffAdminService.currentStaff();
        if (Objects.nonNull(staff)) {
            return staff.getRealName();
        } else {
            return "";
        }
    }
}
